/********************************************************************************
 * <PRE> * 파일 정보 *
 * 1. FileName	: SessionUtil.java
 * 2. Package	: com.ncomz.nzeip.common.util
 * 3. 설명        	: TODO
 * 4. 작성자		: P044826
 * 5. 작성일		: 2013. 11. 29. 오전 9:58:25
 * 6. 설명		:
 * </PRE>
 ********************************************************************************/


package com.sunny.hp.common.util;

import java.io.IOException;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/********************************************************************************
 * <PRE> * 프로그램 정보 *
 * 1. Project		: BEMS2.1
 * 2. Package	: com.ncomz.nzeip.common.util
 * 3. FileName	: SessionUtil.java
 * 4. 작성자		: P044826
 * 5. 작성일		: 2013. 11. 29. 오전 9:58:25
 * 6. 설명			:
 * </PRE>
 ********************************************************************************/

public class SessionUtil {
	
	private HttpSession session;
	private HttpServletRequest request;
    private LinkedHashMap<String, String> userSession;
	public SessionUtil() throws IOException  {
		ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
		this.request = sra.getRequest();
		this.session = this.request.getSession();
		this.userSession = (LinkedHashMap<String, String>)this.session.getAttribute("userSession");
	}
	
	public LinkedHashMap<String, String> getUserSession(){
		return userSession;
	}
	
	public String getSessionParameter(Object paramKey){
		//System.out.println("userSession ==> " + userSession);
		return userSession.get(paramKey+"")+"";
	}
	public String getSessionParameter(Object paramKey, String defaultStr){
		String returnValue = defaultStr;
		if(userSession == null){
			returnValue = "";
		}else{
			returnValue = userSession.get(paramKey+"") == null? "" : userSession.get(paramKey) ;
		}
		return returnValue;
	}
	
	public void putSessionParameter(String key, String value){
		userSession.put(key, value);
		session.setAttribute("userSession", userSession);
	}
}
